#ifndef SMLOG_H
#define SMLOG_H

#define SMLOG_SM_NAME               "sapimapiDebugServerSharedMemory"
#define SMLOG_SM_MUTEX_NAME         "sapimapiDebugServerMutex"
#define SMLOG_SM_SERVEREVENT_NAME   "sapimapiDebugServerServerEventName"
#define SMLOG_SM_CLIENTEVENT_NAME   "sapimapiDebugServerClientEventName"

//Memory sizes are in bytes
#define SMLOG_SM_MEM_MIN            127
#define SMLOG_SM_MEM_MAX            2100000

#define SMLOG_SM_DEFAULT_TIMEOUT    2000
#define SMLOG_SM_DATATYPE_STRING    1

#define SMLOG_SM_SUCCESS                0

#define SMLOG_SM_ERR_GENERAL_ERROR      -1
#define SMLOG_SM_ERR_NO_MEMORY          -2
#define SMLOG_SM_ERR_NO_SHARED_MEMORY   -3
#define SMLOG_SM_ERR_INVALID_PARAMETER  -4
#define SMLOG_SM_ERR_MUTEX_TIMEOUT      -5
#define SMLOG_SM_ERR_SERVER_EVENT_TIMEOUT   -6

/* The shared memory logging functions */
typedef struct debugServerCommunicationData_
{
    DWORD serverPid;        // Set by server ( once )
    DWORD maxMemSize;       // Set by server ( once )
    DWORD dataSize;         // Set by client ( on every write )
    DWORD dataType;         // Set by client ( on every write )
    wchar_t  data;        // Set by client ( on every write )
} debugServerCommunicationData;

typedef struct debugServerContext_
{
    HANDLE fileMap;
    HANDLE mutex;
    HANDLE serverEvent;
    HANDLE clientEvent;
    DWORD  status;
    DWORD  timeout; /* Wait timeout in milliseconds */
    debugServerCommunicationData *data;
} debugServerContext;

int  smlog_write( debugServerContext *smlog_server_context, wchar_t *str );
int  smlog_init(int timeout, debugServerContext **smlog_server_context);
void releaseAllSharedMemoryResources(debugServerContext *smlog_server_context);

#endif /* SMLOG_H */
